Completed
Branch erdiko2 (40e193)
by John
04:03
created

gulp.task(ꞌbootstrap-scriptsꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 5
rs 9.4285
c 1
b 0
f 0
cc 1
nc 1
nop 1
1
'use strict';
2
3
// Useful vars for configuring in your environment
4
/*-------------------------------------------------------------------------------------------------*/
5
6
// var parentThemeRoot  = "../../../vendor/erdiko/wordpress/themes/clean-blog/"; // for themes updated with composer
7
var renderedThemeRoot  = "../../public/";
8
9
var themeName       = "bootstrap";
10
var renderedTheme   = renderedThemeRoot+'themes/'+themeName;
11
12
var jQueryJs        = "node_modules/jquery/dist/jquery.js";
13
var bootstrapJs     = "node_modules/bootstrap-sass/assets/javascripts/bootstrap.js";
14
// var cleanBlogJs     = parentThemeRoot+"scripts/clean-blog.js";
15
16
17
// Boilerplate & Setup
18
/*-------------------------------------------------------------------------------------------------*/
19
20
var gulp = require('gulp');
21
22
// load plugins from package.json file
23
var $ = require('gulp-load-plugins')();
24
    $.del = require('del');
25
    $.runSequence = require('run-sequence');
26
27
// Make 'build' the default task
28
gulp.task('default', function() {
29
   gulp.start('build');
30
});
31
32
// Notify when build is complete
33
gulp.task('notify:buildComplete', function(callback) {
34
   $.notify().write("Build Complete");
35
   callback();
36
});
37
38
// Empty 'stage' directory so we can start fresh
39
gulp.task('clean:stage', function(callback) {
40
   $.del([
41
      'stage/**/*',
42
  ], callback);
43
});
44
45
46
// Main Tasks
47
/*-------------------------------------------------------------------------------------------------*/
48
49
// build - The main task that runs all subtasks
50
gulp.task('build', function(callback) {
51
   $.runSequence(
52
      'clean:stage',
53
      ['styles', 'bootstrap-scripts', 'jquery-scripts', 'scripts'],
54
      ['minify-css', 'minify-js'],
55
      'notify:buildComplete',
56
      callback
57
   );
58
});
59
60
61
// Subtasks
62
/*-------------------------------------------------------------------------------------------------*/
63
64
65
// Compile SASS
66
gulp.task('styles', function(callback) {
67
   return gulp.src('styles/**/*.scss')
68
      .pipe($.order([
69
          "styles.css",
70
          "**/*.scss"
71
      ]))
72
      // Load existing internal sourcemap
73
      .pipe($.sourcemaps.init())
74
      // generate CSS from SASS
75
      .pipe($.sass())
76
      // Catch any errors and prevent them from crashing gulp
77
      .on('error', function (error) {
78
         $.notify().write(error);
79
         this.emit('end');
80
      })
81
      // autoprefix CSS using bootstrap standards
82
      .pipe($.autoprefixer({
83
         browsers: [
84
            "Android 2.3",
85
            "Android >= 4",
86
            "Chrome >= 20",
87
            "Firefox >= 24",
88
            "Explorer >= 8",
89
            "iOS >= 6",
90
            "Opera >= 12",
91
            "Safari >= 6"
92
         ],
93
         remove: false
94
      }))
95
      // Write final .map file
96
      .pipe($.sourcemaps.write())
97
      // move files to stage
98
      .pipe(gulp.dest('stage/styles'), callback);
99
});
100
101
// Javascript
102
gulp.task('scripts', function(callback) {
103
   return gulp.src('scripts/**/*.js')
104
      // copy scripts to stage
105
      .pipe(gulp.dest('stage/scripts'), callback);
106
});
107
108
// Bootstrap Javascript
109
gulp.task('bootstrap-scripts', function(callback) {
110
   return gulp.src(bootstrapJs)
111
      // copy scripts to stage
112
      .pipe(gulp.dest('stage/scripts/vendor'), callback);
113
});
114
115
// jQuery Javascript
116
gulp.task('jquery-scripts', function(callback) {
117
   return gulp.src(jQueryJs)
118
      // copy scripts to stage
119
      .pipe(gulp.dest('stage/scripts/vendor'), callback);
120
});
121
122
// Minify CSS and put it in the public dir
123
gulp.task('minify-css', function() {
124
  return gulp.src('stage/styles/**/*.css')
125
     .pipe($.cleanCss({
126
        processImport: false
127
     }))
128
     .pipe($.rename({
129
        basename: 'main',
130
        suffix: '.min',
131
        extname: '.css'
132
     }))
133
    .pipe(gulp.dest(renderedTheme+'/css'));
134
});
135
136
// minify JS and put in the public dir
137
gulp.task('minify-js', function () {
138
139
   return gulp.src(['stage/scripts/**/*.js'])
140
      .pipe($.order([
141
        "vendor/jquery.js",
142
        "vendor/bootstrap.js",
143
        "vendor/*.js",
144
        "**/*.js"
145
      ]))
146
      .pipe($.concat('scripts.min.js'))
147
      .pipe($.uglify())
148
      .pipe(gulp.dest(renderedTheme+'/js'));
149
});
150